#!/usr/bin/python

import datetime
import time
import commands
import re

dt = datetime.datetime
d = {}
ld = []
li = []
log = []
x = commands.getoutput('ifconfig -a')
a = x.split('\n\n')
for i in range(len(a)):
    p1 = re.search(r'([a-z]+)', a[i])
    dv = ''.join(p1.groups())
    if dv == 'lo':
        ld.append(dv)
    else:
        p2 = re.search(r'([a-z]+)(\d+)', a[i])
        if p2:
            dv = ''.join(p2.groups())
            ld.append(dv)
        else:
            dv = 'unknowndevice'
    if 'inet addr' in a[i]:
        y = re.search(r'inet addr:{1}([\d]+)(.{1})([\d]+)(.{1})([\d]+)(.{1})([\d]+)'r'', a[i])
        li.append(''.join(y.groups()))
    
    else:
        li.append('None')
while True:
    try:
        for i in range(len(ld)):
            d[ld[i]] = li[i]
            d['time'] = str(dt.now())
        #log.append(str(d))
        #print log
        print d
        time.sleep(5)
    except KeyboardInterrupt:
        print ''
        quit()
